import 'package:flutter/material.dart';
import 'package:flutter_mode/zjw/data_transfer/ReduxUtil.dart' as RD;
import 'package:flutter_redux/flutter_redux.dart';

class ReduxUnderScreen extends StatefulWidget {
  @override
  _ReduxUnderScreenState createState() => _ReduxUnderScreenState();
}

class _ReduxUnderScreenState extends State<ReduxUnderScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ReduxUnderScreen'),
      ),
      body: Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text(
              'You have pushed the button this many times:',
            ),
            StoreConnector<RD.CountState, int>(
              converter: (store) => store.state.count,
              builder: (context, count) {
                return Text(
                  count.toString(),
                  style: Theme.of(context).textTheme.bodyLarge,
                );
              },
            ),
          ],
        ),
      ),
      /* 第七步：发出action
       同样，我们还是使用StoreConnector<S,ViewModel>。这里由于是发出了一个动作，所以是VoidCallback。
       store.dispatch发起一个action，任何中间件都会拦截该操作,在运行中间件后，操作将被发送到给定的reducer生成新的状态，并更新状态树。
       */
      floatingActionButton: StoreConnector<RD.CountState, VoidCallback>(
        converter: (store) {
          return () => store.dispatch(RD.Action.increment);
        },
        builder: (context, callback) {
          return FloatingActionButton(
            onPressed: callback,
            child: Icon(Icons.add),
          );
        },
      ),
    );
  }
}
